// js运行时环境
let {KEY,ID,BASE} = require('../config/index')
function $http(url,method="GET",data={}) {
    return new Promise((resolve, reject) => {
        uni.request({
            url: BASE+url,
            method,
            data,
            header:{
                "X-LC-Id": ID,
                "X-LC-Key": KEY,
                "Content-Type": "application/json"
            },
            success: (res) => {
                resolve(res) //给到then
            },
            fail:(err)=>{
                reject(err) //给到catch
            }
        })
    })
}

function $get(url,data={}){
    return $http(url,'GET',data)
}

function $post(url,data={}){
    return $http(url,'POST',data)
}

module.exports = {
    $http,
    $get,
    $post
}